﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using LEARNREN.COM.UI;
using LEARNREN.COM.Entity;
using LEARNREN.COM.BLL;
using LEARNREN.COM.Entity.Enum;

namespace LEARNREN.COM.WebSite
{
    public partial class Default : BasePage
    {
        protected IEnumerable<Catalogue> productCatalogueList = null;
        protected IEnumerable<Article> LastArticleList = null;
        protected List<Product> ProductList = null;
        protected IEnumerable<Project> ProjectList = null;        

        private ArticleLogic articleLogic = null;
        private ProductLogic productLogic = null;
        private ProjectLogic projectLogic = null;
        private CustomSectionLogic customSectionLogic = null;
        private CatalogueLogic catalogicLogic = null;

        protected void Page_Load(object sender, EventArgs e)
        {
            Initialize();
        }

        private void Initialize()
        {
            productCatalogueList = catalogicLogic.GetConfigedProductCatalogueCollection();
            LastArticleList = articleLogic.GetListDESC(p => p.Id).Take(9);
            ProductList = productLogic.GetListDESC(p => p.IsRecommend, p => p.Id).Take(12).ToList();
            ProjectList = projectLogic.GetListDESC(p => p.Id).Take(4);

            CustomSection customSection = customSectionLogic.GetById(1);
            if (customSection != null)
            {
                this.ltAboutUs.Text = customSection.Content;
            }
        }

        protected override void InitLogic()
        {
            articleLogic = new ArticleLogic();
            productLogic = new ProductLogic();
            projectLogic = new ProjectLogic();
            customSectionLogic = new CustomSectionLogic();
            catalogicLogic = new CatalogueLogic();
        }

        protected override void DisposeLogic()
        {
            if (articleLogic != null)
            {
                articleLogic.Dispose();
                articleLogic = null;
            }
            if (productLogic == null)
            {
                productLogic.Dispose();
                productLogic = null;
            }
            if (projectLogic != null)
            {
                projectLogic.Dispose();
                projectLogic = null;
            }
            if (customSectionLogic != null)
            {
                customSectionLogic.Dispose();
                customSectionLogic = null;
            }
            if (catalogicLogic != null)
            {
                catalogicLogic.Dispose();
                catalogicLogic = null;
            }            
        }
    }
}